<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>老师查询</title>

    <link rel="stylesheet" type="text/css" href="/static/js/layui-v2.5.7/layui/css/layui.css">
    <script type="text/javascript" src="/static/js/layui-v2.5.7/layui/layui.js"></script>
    <script type="text/javascript" src="/static/js/myJs.js"></script>


</head>
<body>


<div style="text-align: center">
    <h2>
        老师列表
        <!--        <a href="InsertTeacher" class="layui-btn layui-btn-xs layui-bg-cyan">-->
        <!--            <i class="layui-icon">&#xe608;</i>-->
        <!--            添加-->
        <!--        </a>-->

        <a href="/studentLayer" class="layui-btn layui-btn-radius layui-btn-xs">
            菜单
            <i class="layui-icon">&#xe614;</i>
        </a>
    </h2>


    <table id="table" lay-filter="table" class="layui-table" style="width:auto;height:auto;margin:auto">
        <!--    <colgroup></colgroup>-->
        <!--    <tr>-->
        <!--        <th>老师姓名</th>-->
        <!--        <th>老师密码</th>-->
        <!--        <th>老师性别</th>-->
        <!--        <th>老师年龄</th>-->
        <!--        <th>教学科目</th>-->
        <!--        <th>时间</th>-->
        <!--        <th>操作</th>-->

        <!--    </tr>-->
        <!--    <tbody id="Teacher">-->

        <!--    </tbody>-->

    </table>

</div>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
        <button class="layui-btn layui-btn-sm layui-btn-radius layui-btn-normal" lay-event="add">添加班级</button>
    </div>
</script>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="SexTemplet">
    {{# if(d.sex=='男'){ }}
    <span style="color: #01AAED">{{d.sex}}</span>
    {{# }else if(d.sex == '女'){ }}
    <span style="color: #1e347b">{{d.sex}}</span>
    {{# } }}
</script>


<script>
    // $(document).ready(function () {
    //
    //     $.ajax({
    //         dataType: "json",
    //         url: "/studentLayer/Teacher/SelectTeacher",
    //         method: "POST",
    //         success: function (ajax_Teacher) {
    //             var html;
    //             if (ajax_Teacher.code == 0) {
    //                 ajax_Teacher.ajaxdata.forEach(function (value, index) {
    //                     html = html
    //                         + "<tr>"
    //                         + "<td>" + value.name + "</td>"
    //                         + "<td>" + value.password + "</td>"
    //                         + "<td>" + value.sex + "</td>"
    //                         + "<td>" + value.age + "</td>"
    //                         + "<td>" + value.c_name + "</td>"
    //                         + "<td>" + value.create_time + "</td>"
    //                         + "<td>"
    //                         + "<a href='DeleteTeacher?id=" + value.id + "'>" + "删除" + "</a>"
    //                         + "&nbsp;&nbsp;"
    //                         + "<a onclick='UP("+value.id+");' href='UpdateTeacher?id=" + value.id + "'>" + "修改" + "</a>"
    //                         + "</td>"
    //                         + "</tr>";
    //                 })
    //                 $('#Teacher').html(html);
    //             } else {
    //                 window.location.href = "/studentLayer";
    //             }
    //         }
    //
    //
    //     })
    //
    //
    // })
    //
    // function UP(id) {
    //     alert(id);
    //     $.ajax({
    //         dataType: "json",
    //         type:"GET",
    //         url:"/studentLayer/Teacher/UpdateTeacher",
    //         data:{"id":id}
    //     })
    // }


    layui.use(['table'], function () {
        var table = layui.table;

        table.render({
            elem: '#table',
            url: "/studentLayer/Teacher/SelectTeacher",
            // width:"563",
            page: true,
            toolbar: '#toolbarDemo',
            parseData: function (res) {
                return {
                    'code': res.code,
                    'msg': res.msg,
                    "data": res.ajaxdata,
                    "count":res.count
                };
            },
            cols: [[
                {field: 'id', title: 'ID', sort: true, fixed: 'left', align: 'center'},
                {field: 'name', title: '老师姓名', align: 'center'},
                {field: 'password', title: '老师密码', align: 'center'},
                {field: 'sex', title: '老师性别', align: 'center', sort: true, templet: '#SexTemplet'},
                {field: 'age', title: '老师年龄', sort: true, align: 'center'},
                {field: 'c_name', title: '教学科目', align: 'center'},
                {field: 'create_time', title: '时间', align: 'center'},
                {field: 'id', title: '操作', toolbar: '#barDemo', align: 'center'},
                {type: 'checkbox', width: '60', fixed: 'right'}
            ]]
        });


        table.on('toolbar(table)', function (obj) {
            var checkStatus = table.checkStatus('table');
            var layEvent = obj.event;
            switch (layEvent) {
                case'add':
                    layer.open({
                        type: 2,
                        title: '添加',
                        area: ['100%', '100%'],
                        maxmin: true,
                        content: '/studentLayer/Teacher/InsertTeacher',
                    })
                    break;
                case'getCheckData':
                    layer.msg(JSON.stringify(checkStatus.data));
                    break;
                case'getCheckLength':
                    layer.msg('选中' + checkStatus.data.length + '条');
                    break;
                case'isAll':
                    layer.msg(checkStatus.isAll ? '已全选' : '未全选');
                    break;

            }
        });


        table.on('tool(table)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;
            var tr = obj.tr;
            if (layEvent == 'edit') {
                layer.msg('是否修改', {
                    btn: ['Y', 'N'],
                    yes: function (index, layero) {
                        layer.open({
                            type: 2,
                            title: '修改',
                            area: ['100%', '100%'],
                            maxmin: true,
                            content: '/studentLayer/Teacher/UpdateTeacher?id=' + data.id,
                        })
                    },
                    btn2: function (index, layero) {
                        layer.close(index);
                    }
                })


            } else if (layEvent == 'del') {

                layer.msg('是否删除', {
                    btn: ['Y', 'N'],
                    yes: function (index, layero) {
                        $.ajax({
                            dataType: 'json',
                            type: 'GET',
                            url: '/studentLayer/Teacher/DeleteTeacher',
                            data: {"id": data.id},
                            success: function (ajax) {
                                obj.del();
                                layer.close(index);
                            }
                        })

                    },
                    btn2: function (index, layero) {
                        layer.close(index);
                    }

                });
            }
        })


    })

</script>


</body>
</html>